fix(Listbox): prevent virtualized list from scrolling page on mount#2675
fix(Listbox): prevent virtualized list from scrolling page on mount#2675benjamincanac wants to merge 1 commit into
Conversation
Follow-up to unovue#2666, which fixed the non-virtual path only. A virtualized Listbox still pulled the whole page to itself on mount: `highlightSelected` dropped the `scroll` flag whenever `isVirtual` was true, so a list with no checked item fell through to `highlightFirstItem` (synthetic PageUp → `changeHighlight` with focus + `scrollIntoView`), yanking a below-the-fold listbox into view on load. Thread the mount intent through the `virtualFocusHook` payload (`{ event, scroll }`) so the virtualizer can set its roving-tabindex target without focusing/scrolling on mount, mirroring the non-virtual path. The checked-item branch keeps `scrollToIndex`, which only scrolls the internal listbox container, never the page. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR refactors the virtual focus hook contract in the Listbox component to distinguish between initial mount highlighting and user-driven scrolling. The ChangesVirtual focus hook contract and scroll-aware implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Follow-up to #2666, which fixed the non-virtual path only. A virtualized Listbox still pulled the whole page to itself on mount (same root cause as nuxt/ui#6513).
Root cause
In
ListboxRoot,highlightSelected(event, scroll)dropped thescrollflag wheneverisVirtualwas true — it just calledvirtualFocusHook.trigger(event). So on mount a virtualized list with no checked item (e.g.multiple+ emptyv-model) fell into the hook'selse→highlightFirstItem()→ synthetic PageUp →changeHighlight(firstItem)with default focus +scrollIntoView, yanking a below-the-fold listbox into view on load.Fix
Thread the mount intent through the
virtualFocusHookpayload ({ event, scroll }) so the virtualizer sets its roving-tabindex target without focusing/scrolling on mount, mirroring the non-virtual path. The checked-item branch keepsscrollToIndex— that only scrolls the internal listbox container, never the page.Notes for reviewers
virtualFocusHook's payload shape changed. It lives on the context exposed byinjectListboxRootContext, but it's an internal coordination hook not realistically triggered/consumed externally — no public API or runtime behavior for normal usage changes. Not a breaking change.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests